package com.bmf.core.result;

import lombok.Data;

import java.util.ArrayList;
import java.util.Collection;

/**
 *  分页查询返回对象
 * @date 2020-04-14 16:49
 * @author 
 */
@Data
public class PageResponse<T> {

    /**
     * 数据列表
     */
    private Collection<T> records;

    /**
     * 总记录数
     */
    private int totalCount;

    /**
     * 当前页，从1开始
     */
    private int pageNo;

    /**
     * 分页大小
     */
    private int pageSize;

    public PageResponse() {
        this.setRecords(new ArrayList<>());
        this.setPageNo(0);
        this.setPageSize(0);
        this.setTotalCount(0);

    }

    public PageResponse(PageResponse<Object> page, Collection<T> records) {
        this.records = records;
        this.setPageNo(page.getPageNo());
        this.setPageSize(page.getPageSize());
        this.setTotalCount(page.getTotalCount());
    }

    public PageResponse(Collection<T> records, long totalCount, long pageNo, long pageSize) {
        this.records = records;
        this.totalCount = (int)totalCount;
        this.pageNo = (int)pageNo;
        this.pageSize = (int)pageSize;
    }

}
